package com.hung.nio;
/**
 * title:IntBufferDemo.java
 * author: hungki
 * createTime 18/8/30 下午 1:42
 * version v_1.0
 * Copyright @ 2018 复华创新事业部
 */

import java.nio.IntBuffer;
import java.util.Arrays;

/**
 * className: IntBufferDemo 
 * describe: 
 * author: hungki  
 * createTime 18/8/30 下午 1:42 
 *
 */
public class IntBufferDemo {

    public static void main(String[] args) {

        intBufferWrapTest4();



    }

    private static void intBufferWrapTest4() {
        IntBuffer intBuffer = IntBuffer.allocate(10);
        intBuffer.put(10);
        intBuffer.put(22);
        intBuffer.put(42);
        intBuffer.put(426);

        IntBuffer intBuffer1 = intBuffer.duplicate();

        intBuffer.put(2323);
        intBuffer.flip();
        intBuffer1.flip();

        System.out.println("intBuffer = " + intBuffer);
        System.out.println(" Arrays.toString(intBuffer.array()) = " + Arrays.toString(intBuffer.array()));
        System.out.println("intBuffer.limit() = " + intBuffer.limit());
        System.out.println("intBuffer.capacity() = " + intBuffer.capacity());
        System.out.println("intBuffer1.remaining() = " + intBuffer1.remaining());
        for(int i=0;i<intBuffer.limit();i++){
            System.out.println("intBuffer.get() = " + intBuffer.get());
        }
        for(int i=0;i<intBuffer1.limit();i++){
            System.out.println("intBuffer1.get() = " + intBuffer1.get());
        }

    }

    private static void intBufferWrapTest3() {
        int[] arr =new int[]{3,4,40,6,84};
        IntBuffer intBuffer=IntBuffer.wrap(arr,0,3);

        System.out.println("intBuffer = " + intBuffer);
        System.out.println(" Arrays.toString(intBuffer.array()) = " + Arrays.toString(intBuffer.array()));
        System.out.println("intBuffer.limit() = " + intBuffer.limit());
        System.out.println("intBuffer.capacity() = " + intBuffer.capacity());
        for(int i=0;i<intBuffer.limit();i++){
            System.out.println("intBuffer.get() = " + intBuffer.get());
        }

    }

    private static void intBufferWrapTest2() {
        int[] arr =new int[]{3,4,40,6,84};
        IntBuffer intBuffer=IntBuffer.wrap(arr);

        intBuffer.put(4,223);

        intBuffer.position(4);

        intBuffer.put(334);

        System.out.println("intBuffer = " + intBuffer);
        System.out.println(" Arrays.toString(intBuffer.array()) = " + Arrays.toString(intBuffer.array()));
        System.out.println("intBuffer.limit() = " + intBuffer.limit());
        System.out.println("intBuffer.capacity() = " + intBuffer.capacity());
        intBuffer.flip();
        System.out.println(" =========================" );
        System.out.println("intBuffer = " + intBuffer);
        System.out.println(" Arrays.toString(intBuffer.array()) = " + Arrays.toString(intBuffer.array()));
        System.out.println("intBuffer.limit() = " + intBuffer.limit());
        System.out.println("intBuffer.capacity() = " + intBuffer.capacity());


    }

    private static void intBufferWrapTest() {
        int[] arr =new int[]{3,4,40,6,84};
        IntBuffer intBuffer=IntBuffer.wrap(arr);

        System.out.println("intBuffer = " + intBuffer);
        System.out.println(" Arrays.toString(intBuffer.array()) = " + Arrays.toString(intBuffer.array()));
        System.out.println("intBuffer.limit() = " + intBuffer.limit());
        System.out.println("intBuffer.capacity() = " + intBuffer.capacity());

        intBuffer.flip();
        System.out.println(" =========================" );
        System.out.println("intBuffer = " + intBuffer);
        System.out.println(" Arrays.toString(intBuffer.array()) = " + Arrays.toString(intBuffer.array()));
        System.out.println("intBuffer.limit() = " + intBuffer.limit());
        System.out.println("intBuffer.capacity() = " + intBuffer.capacity());


    }

    private static void intBufferTest() {
        IntBuffer intBuffer = IntBuffer.allocate(10);
        intBuffer.put(10);
        intBuffer.put(22);
        intBuffer.put(42);
        intBuffer.put(426);
        System.out.println("intBuffer = " + intBuffer);
        System.out.println(" Arrays.toString(intBuffer.array()) = " + Arrays.toString(intBuffer.array()));
        System.out.println("intBuffer.limit() = " + intBuffer.limit());
        System.out.println("intBuffer.capacity() = " + intBuffer.capacity());

        intBuffer.flip();
        System.out.println(" =========================" );
        System.out.println("intBuffer = " + intBuffer);
        System.out.println(" Arrays.toString(intBuffer.array()) = " + Arrays.toString(intBuffer.array()));
        System.out.println("intBuffer.limit() = " + intBuffer.limit());
        System.out.println("intBuffer.capacity() = " + intBuffer.capacity());
    }
}
